#!/usr/bin/env python
# -*-coding:utf-8-*-
# File    : liyuqi.py

import os
import sqlite3
import pytest

@pytest.fixture(scope='class')
def dbconnect():
    conn = sqlite3.connect("funds.db")
    print("数据库连接成功")
    yield conn
    conn.close()
    print("数据库连接已关闭")


def test_count(dbconnect):
    cursor = dbconnect.cursor()
    sql = '''select count(1) from fund;'''
    cursor.execute(sql)
    result = cursor.fetchone()[0]
    # 库中实际有11201条数据，因此本条用例实际会失败
    assert result == 11202


class Test_my_class:
    def test_start(self):
        print('start')
        print(dir(self))

    def test_count(self):
        cursor = dbconnect.cursor()
        sql = '''select count(1) from fund;'''
        cursor.execute(sql)
        result = cursor.fetchone()[0]
        # 库中实际有11201条数据，因此本条用例实际会失败
        assert result == 11201

if __name__ == '__main__':
    pytest.main(['-s', os.path.basename(__file__), '--html=report.html'])